home *** CD-ROM | disk | FTP | other *** search
- /* Window.c
- Copyright (c) 1990,1991,1992,1993 by Thomas E. Janzen
- All Rights Reserved
-
- THIS SOFTWARE IS FURNISHED FREE OF CHARGE FOR STUDY AND USE AND MAY
- BE COPIED ONLY FOR PERSONAL USE OR COMPLETELY AS OFFERED WITH NO
- CHANGES FOR FREE DISTRIBUTION. NO TITLE TO AND OWNERSHIP OF THE
- SOFTWARE IS HEREBY TRANSFERRED. THOMAS E. JANZEN ASSUMES NO
- RESPONSIBILITY FOR THE USE OR RELIABILITY OF THIS SOFTWARE.
-
- Thomas E. Janzen
- 208A Olde Derby Road
- Norwood, MA 02062-1761
- (617)769-7733
-
- ** FACILITY:
- **
- ** AlgoRhythms music improviser on Commodore (TM) Amiga (TM)
- ** compiled with SAS/C Amiga Compiler 6.50
- **
- ** ABSTRACT:
- **
- ** Window.c Opens and manages the Workbench-type window used by
- ** AlgoRhythms.
- **
- ** AUTHORS: Thomas E. Janzen
- **
- ** CREATION DATE: 26-MAR-1990
- **
- ** MODIFICATION HISTORY:
- ** DATE NAME DESCRIPTION
- ** 24 SEP 91 T. Janzen use algorhythms.col to specify screen colors
- ** 8 DEC 91 T. Janzen conform to SAS/C 5.10b remove extern from functs
- ** 4 Jan 92 TEJ last changes for 2.0
- ** 12 Oct 93 TEJ remove unecessary library opens/closes.
- ** Change to use AmigaDOS 2.0 libraries.
- ** No longer support interlace.
- ** 30 DEC 93 TEJ Go back to 4 screen colors.
- **--
- */
- #include <stdlib.h>
- #include <stdio.h>
- #include <math.h>
- #include <string.h>
- #include <ctype.h>
- #include <exec/types.h>
- #include <exec/nodes.h>
- #include <exec/lists.h>
- #include <intuition/intuition.h>
- #include <intuition/screens.h>
- #include <graphics/text.h>
- #include <proto/asl.h>
- #include <proto/exec.h>
- #include <proto/graphics.h>
- #include <proto/intuition.h>
- #include <proto/dos.h>
- #include <proto/gadtools.h>
- #include <graphics/display.h>
- #include "Window.h"
-
- #define TRUE 1
- #define FALSE 0
-
- /* WINDOW */
- struct Screen *main_screen;
- struct Window *w;
- struct RastPort *rast_port;
- struct ViewPort *view_port;
- void *vi;
-
- struct TextAttr font_choice = {(STRPTR)"topaz.font", TOPAZ_EIGHTY, 0, 0};
-
- static void StripIntuiMessages(struct MsgPort *mp, struct Window *win);
-
- void open_wind(void)
- /*
- ** FUNCTIONAL DESCRIPTION:
- **
- ** DESIGN:
- ** ROUTINE
- ** : open color file
- ** : IF file opened
- ** : : read in intensities for reds, greens, and blues
- ** : : close the color file
- ** : ENDIF
- ** : OpenScreen()
- ** : FOR color_index = 0 to 7
- ** : : Set the colors
- ** : ENDFOR
- ** : copy screen pointer to new window
- ** : copy rastport from window struct
- ** : copy ViewPort from screen
- ** ENDROUTINE
- */
- {
- static char tmp_str[80];
- auto struct ColorSpec colors[]
- = {{0, 0x0, 0x9, 0xF}, {1, 0x0, 0x0, 0x6},
- {2, 0xB, 0xF, 0xF}, {3, 0x0, 0xF, 0xF}, {-1,0x0, 0x0, 0x0}};
- auto FILE *color_file;
- static char screen_title[55] =
- "AlgoRhythms ©1993 Thomas E. Janzen All Rights Reserved";
- auto UWORD pens[] = {0xFFFF};
- color_file = fopen(T_COLOR_FILE, "r");
- if (color_file != NULL)
- {
- fgets(tmp_str, 80, color_file);
- tmp_str[79] = '\0';
- sscanf(tmp_str, "%hd %hd %hd %hd",
- &(colors[0].Red), &(colors[1].Red), &(colors[2].Red),
- &(colors[3].Red));
- fgets(tmp_str, 80, color_file);
- tmp_str[79] = '\0';
- sscanf(tmp_str, "%hd %hd %hd %hd",
- &(colors[0].Green), &(colors[1].Green), &(colors[2].Green),
- &(colors[3].Green));
- fgets(tmp_str, 80, color_file);
- tmp_str[79] = '\0';
- sscanf(tmp_str, "%hd %hd %hd %hd",
- &(colors[0].Blue), &(colors[1].Blue), &(colors[2].Blue),
- &(colors[3].Blue));
- fclose(color_file);
- }
- main_screen = OpenScreenTags( NULL,
- SA_Pens, (ULONG)pens,
- SA_DisplayID, HIRES_KEY,
- SA_Depth, C_WINDOW_DEPTH,
- SA_Title, (ULONG) screen_title,
- SA_Height, 200,
- SA_Colors, colors,
- SA_Font, &font_choice,
- TAG_DONE);
- if (NULL == (vi = GetVisualInfo(main_screen, TAG_END)))
- {
- ;
- }
- w = OpenWindowTags(NULL,
- WA_Left, 0,
- WA_Top, 10,
- WA_Width, 640,
- WA_Height, 190,
- WA_MinWidth, 400,
- WA_MinHeight, 190,
- WA_MaxWidth, ~0,
- WA_MaxHeight, ~0,
- WA_CloseGadget, TRUE,
- WA_SizeGadget, TRUE,
- WA_DepthGadget, TRUE,
- WA_DragBar, TRUE,
- WA_Activate, TRUE,
- WA_NoCareRefresh,TRUE,
- WA_CustomScreen, main_screen,
- WA_Title, "Random Form",
- WA_IDCMP, IDCMP_REQSET | IDCMP_NEWSIZE | IDCMP_CLOSEWINDOW |
- IDCMP_MENUPICK | IDCMP_GADGETUP,
- WA_Flags, WFLG_SMART_REFRESH | WFLG_GIMMEZEROZERO,
- TAG_DONE);
- rast_port = w->RPort; /* Get the raster port pointer */
- view_port = &w->WScreen->ViewPort; /* Get the view port pointer */
- return;
- }
-
- void shut_window(void)
- /*
- ** FUNCTIONAL DESCRIPTION:
- ** Shuts down libraries, windows, and screen.
- **
- ** DESIGN:
- ** ROUTINE
- ** : CloseWindow()
- ** : CloseScreen()
- ** : OpenWorkBench()
- ** ENDROUTINE
- */
- {
- CloseWindowSafely(w);
- CloseScreen(main_screen);
- FreeVisualInfo(vi);
- OpenWorkBench();
- return;
- }
- /*
- ** CloseWindowSafely and StripIntuiMessages are taken from the
- ** Amiga ROM Kernel Reference Manual, Includes and Autodocs,
- ** for V2, P 314 under the autodocs for CloseWindow() with minor
- ** modifications.
- */
- void CloseWindowSafely(struct Window *win)
- {
- Forbid(); /* prevent Intuition race conditions */
- /* Return to sender - addressee unknown */
- StripIntuiMessages(win->UserPort, win);
- win->UserPort = NULL; /* zero out shared port without hurting others */
- ModifyIDCMP(win, 0L); /* Clear out IDCMP flags to stop events */
- Permit(); /* Done hogging the OS */
- CloseWindow(win);
-
- return;
- }
-
- static void StripIntuiMessages(struct MsgPort *mp, struct Window *win)
- {
- auto struct IntuiMessage *msg;
- auto struct Node *succ;
-
- msg = ( struct IntuiMessage *)mp->mp_MsgList.lh_Head;
- while(succ = msg->ExecMessage.mn_Node.ln_Succ)
- {
- if(msg->IDCMPWindow == win)
- {
- Remove((struct Node *)msg);
- ReplyMsg((struct Message *)msg);
- }
- msg = (struct IntuiMessage *) succ;
- }
- return;
- }
-